package com.lizhe.conditional.config;

import com.lizhe.conditional.entity.Village;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类描述:
 *
 * @author Administrator
 * @create 2022-06-13 22:31
 */

// 在application.yml 配置里"lz.effect"，对应的值为true (注意yml的配置要有空格，遇到的坑)
// 如果配置为false，则该configuration不生效；为true则生效。

@Configuration
@ConditionalOnProperty(prefix = "lz", name = "effect", havingValue = "true")
public class VeriConditionalPropertyConfig {

    // village工厂类，根据配置文件来判断是否加载，ConditionalOnProperty配置也可以作用到方法
    @Bean
    // @ConditionalOnProperty(prefix = "lz", name = "effect", havingValue = "true")
    public Village villageBean() {
        Village village = new Village();
        village.setName("东徐庄");
        return village;
    }
}